/**
 *
 * @author Doan Tuan Anh
 */

import javax.microedition.lcdui.game.Sprite;
import javax.microedition.lcdui.Image;

public class Splash extends Sprite{
    
    int posX, posY;
    static final int TOTAL_FRAME = 8;
    private int[] FRAMES;
    private boolean running;
    
    public Splash(int initialX, int initialY) throws Exception {
    
        super(Image.createImage("/splash2.png"), Image.createImage("/splash2.png").getWidth() / TOTAL_FRAME, Image.createImage("/splash2.png").getHeight());
        
        defineReferencePixel(super.getWidth() / 2, super.getHeight() / 2);
        
        FRAMES = new int[TOTAL_FRAME];
        for(int i = 0; i < TOTAL_FRAME; i++) FRAMES[i] = i;
        running = false;
        
        posX = initialX;
        posY = initialY;
        setRefPixelPosition(posX, posY);
        setVisible(false);
    }
    
    void reset()
    {
        setVisible(false);
        running = false;
    }
    
    boolean isRunning()
    {
        return running;
    }
    
    void setRunning(int x, int y)
    {
        setRefPixelPosition(x, y);
        setVisible(true);
        running = true;
    }
    
    synchronized void advance() {
        if(running) {
           nextFrame();
           if(getFrame() == 0) reset();     
        }
    }
}
